/***
 * create by zm
 * 2020/03/17
 *
 * ***/
import Vue from 'vue';
import axios from 'axios';
import wx from 'weixin-js-sdk';
export default {
  wxShare: function(title, desc, link, img, type, callBack) {
    let a = encodeURIComponent(location.href.split('#')[0]);
    var params = new URLSearchParams();
    params.append('urlStr', a);
    // params.append('type', '63'); //生产
    params.append('type', '14'); //测试

    axios({
      method: 'post',
      // url: 'http://wxqy.chinalife-p.com.cn:8081/wechatBase-web/external/getWXConfigByType', //生产
      url: 'http://wxqytest.chinalife-p.com.cn:30013/wechatBase-web/external/getWXConfigByType', //测试
      data: params,
    })
      .then((data) => {
        // alert(JSON.stringify(data.data));
        var obj = JSON.parse(data.data);
        wx.config({
          beta: true,
          debug: false,
          appId: obj.appId,
          timestamp: obj.timestamp,
          nonceStr: obj.noncestr,
          signature: obj.signature,
          jsApiList: [
            'hideMenuItems',
            'showMenuItems',
            'hideOptionMenu',
            'showOptionMenu',
            'onMenuShareTimeline',
            'onMenuShareWechat',
            'onMenuShareAppMessage',
            'getLocation',
          ],
        });
        wx.ready(function() {
          wx.hideOptionMenu();
          wx.hideMenuItems({
            menuList: [
              'menuItem:share:appMessage',
              'menuItem:share:timeline',
              'menuItem:share:qq',
              'menuItem:share:weiboApp',
              'menuItem:share:facebook',
              'menuItem:share:QZone',
            ],
          });
        });
      })
      .catch((err) => {
        console.log('err', err);
      });
  },
};
